<?php
/**
 * Created by PhpStorm .
 * User: {Administrator}
 * Date: {2022/9/20 18:51}
 * Author: '树叶'
 * Email: 'ayunu@qq.com'
 * Motto Info: '理想如果不向现实做一点点屈服，那么理想也将归于尘土。'
 */

namespace wxpay;

class Car
{
    protected $open_id = '2275480dfe3c1d66118424a5f33d8772'; // 车架Id
    protected $token = '7f3b52d0fe783ef536634fdd3a130677'; // 车架秘钥

    public function parse($vin)
    {
        if (!$vin)
        {
            var_dump('请上传车架号');
            return false;
        }
        $url = 'https://sapi.007vin.com/api/cars/vin?open_id='.$this->open_id.'&token='.$this->token.'&vin='.$vin;
        $data = request_url($url);
        $response = json_decode($data,true);
        return $response;

    }

    /**
     * 车牌获取车型
     */
    public function plateModel($name)
    {
        $url  = 'https://api.chinadatapay.com/government/traffic/9696';
        $post = [
            'key' => 'da978b16ec9cb94a73e1b139bdff9294',
            'plateNumber' => $name
        ];
        $data = request_url($url,$post);
        $data = json_decode($data,true);
        if ($data['code'] != "10000")
        {
            return false;
        }
        return $data['data'];
    }


    /**
     * 营业执照识别
     */
    public function yyzLicense($imageId)
    {

        $post = [
            'key' => 'b4ec0c2390a76f114e56f4157e76642d',
            'imageId' =>$imageId
        ];
        $url = 'https://api.chinadatapay.com/trade/user/9025';
        $data = re_url($url, $post);
        $data = json_decode($data,true);

        if ($data['code'] == '10000')
        {
            $response = $this->safety($data['data']);
            if ($response == true)
            {
                echo '';
                return true;
            }else{
                return false;
            }
        }else{
            return false;
        }
    }


    /**
     * 企业二要素:企业认证
     */
    public function safety($data)
    {
        if (empty($data))
        {
            return false;
        }
        $get = [
            'key' => 'b5fc58402b9cb5df04c3f2c6c322f363',
            'entName'     => $data['name'],
            'creditcode'  => $data['creditcode'],
        ];
        $url = 'https://api.chinadatapay.com/communication/personal/9801';
        $resData = request_url($url,$get);
        $resData = json_decode($resData,true);

        if ($resData['code'] == '10000')
        {
            if ($resData['data']['state'] == 1)
            {
                return true;
            }else{
                return false;
            }
        }else{
            echo '验证失败';
            return false;
        }


        halt($resData);
    }
}